using TMPro;
using UnityEngine;
using UnityEngine.UI;
//item物品
public class ItemDataView : MonoBehaviour
{
    public GameObject bagBgObj { get; set; }
    public GameObject msgObj { get; set; }
    public GameObject uiPage { get; set; }

    public ItemDatas_SO itemDatas_SO;
    // Start is called before the first frame update
    public void Init(ItemDatas_SO data)
    {
        itemDatas_SO = data; // 保存数据
        GetComponent<Image>().sprite = itemDatas_SO.itemIcon;
        transform.Find("Num").GetComponent<TextMeshProUGUI>().text = $"{itemDatas_SO.itemNum}";
        closeMsg();

    }

    public void selectItem()
    {
        closeMsg();
        transform.parent.transform.Find("kuang").gameObject.SetActive(true);
        msgObj.transform.Find("itemName").GetComponent<TextMeshProUGUI>().text = itemDatas_SO.itemName;
        msgObj.transform.Find("itemMsg").GetComponent<TextMeshProUGUI>().text = itemDatas_SO.itemMsg;
        msgObj.transform.Find("num").GetComponent<TextMeshProUGUI>().text = $"数量：{itemDatas_SO.itemNum}";

        uiPage.GetComponent<BagUIPage>().itemDatas_SO = itemDatas_SO;
        uiPage.GetComponent<BagUIPage>().item = gameObject;

        msgObj.transform.Find("removeItemBtn").gameObject.SetActive(true);
        msgObj.transform.Find("useItemBtn").gameObject.SetActive(true);

    }
    public void closeMsg()
    {
        foreach (Transform item in bagBgObj.transform)
        {
            item.Find("kuang").gameObject.SetActive(false);
        }
    }
    // Update is called once per frame
    void Update()
    {

    }
}
